package com.fzkj.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fzkj.common.annotation.Log;
import com.fzkj.common.core.controller.BaseController;
import com.fzkj.common.core.domain.AjaxResult;
import com.fzkj.common.core.page.TableDataInfo;
import com.fzkj.common.enums.BusinessType;
import com.fzkj.common.utils.poi.ExcelUtil;
import com.fzkj.project.entiy.PracticeTask;
import com.fzkj.project.service.IPracticeTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 实践任务Controller
 *
 * @author zhangmx
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/project/task")
public class PracticeTaskController extends BaseController {
    @Autowired
    private IPracticeTaskService practiceTaskService;

    /**
     * 查询实践任务列表
     */
    @RequiresPermissions("project:task:list")
    @GetMapping("/list")
    public TableDataInfo list(PracticeTask practiceTask) {
        startPage();
        List<PracticeTask> list = practiceTaskService.selectPracticeTaskList(practiceTask);
        return getDataTable(list);
    }

    /**
     * 导出实践任务列表
     */
    @RequiresPermissions("project:task:export")
    @Log(title = "实践任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeTask practiceTask) {
        List<PracticeTask> list = practiceTaskService.selectPracticeTaskList(practiceTask);
        ExcelUtil<PracticeTask> util = new ExcelUtil<PracticeTask>(PracticeTask.class);
        util.exportExcel(response, list, "实践任务数据");
    }

    /**
     * 获取实践任务详细信息
     */
    @RequiresPermissions("project:task:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(practiceTaskService.selectPracticeTaskById(id));
    }

    /**
     * 新增实践任务
     */
    @RequiresPermissions("project:task:add")
    @Log(title = "实践任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeTask practiceTask) {
        return toAjax(practiceTaskService.insertPracticeTask(practiceTask));
    }

    /**
     * 修改实践任务
     */
    @RequiresPermissions("project:task:edit")
    @Log(title = "实践任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeTask practiceTask) {
        return toAjax(practiceTaskService.updatePracticeTask(practiceTask));
    }

    /**
     * 删除实践任务
     */
    @RequiresPermissions("project:task:remove")
    @Log(title = "实践任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(practiceTaskService.deletePracticeTaskByIds(ids));
    }
}
